﻿using System;
using System.Linq;

namespace Fee.ViewModel
{
    public class StationSimpleModel
    {
        public StationSimpleModel()
        {
        }

        public StationSimpleModel(Station station)
        {
            if (station == null) throw new ArgumentNullException(nameof(station));
            Id = station.Id;
            Code = station.Code;
            if (station.District != null) District = new DistrictSimpleViewModel(station.District);

            if (station.OrderDistrict != null) OrderDistrict = new DistrictSimpleViewModel(station.OrderDistrict);
        }

        public DistrictSimpleViewModel OrderDistrict { get; set; }

        public DistrictSimpleViewModel District { get; set; }

        public string Code { get; set; }

        public int Id { get; set; }
        public string Name { get; set; }

        public Station GetFrom(FeeDbContext context)
        {
            if (Id == 0)
                throw new ArgumentException("StationSimpleModel 转换出错，输入id不能为0");
            return context.Stations.FirstOrDefault(f => f.Id == Id);
        }
    }
}